﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

using DTO_QLNS;

namespace ADO_QLNS
{
    public abstract class QLNS_ADO
    {
        protected static ADOHelper _Helper = new ADOHelper(new Utils.SqlDataProvider());

        public void Insert(TransferObject dtoInsert)
        {
            _Helper.Connect();
            {
                _Helper.exeNonQuery(InsertString(dtoInsert));
            }
            _Helper.Disconnect();
        }

        public void Update(TransferObject dtoUpdate)
        {
            _Helper.Connect();
            {
                _Helper.exeNonQuery(UpdateString(dtoUpdate));
            }
            _Helper.Disconnect();
        }

        public void Delete(TransferObject dtoDelete)
        {
            _Helper.Connect();
            {
                _Helper.exeNonQuery(DeleteString(dtoDelete));
            }
            _Helper.Disconnect();
        }

        protected ArrayList ConvertDataSetToArrayList(DataSet dataset)
        {
            ArrayList arrlist = new ArrayList();
            DataTable dt = dataset.Tables[0];
            int i, n = dt.Rows.Count;
            for (i = 0; i < n; ++i)
            {
                object obj = GetDataFromDataRow(dt, i);
                arrlist.Add(obj);
            }

            return arrlist;
        }

        public abstract string InsertString(TransferObject dto);
        public abstract string UpdateString(TransferObject dto);
        public abstract string DeleteString(TransferObject dto);
        protected abstract object GetDataFromDataRow(DataTable dt, int i);
    }
}
